#include "StdAfx.h"
#include "commandsur.h"
#include "dentityfactory.h"
#include "ddocument.h"
#include "dentitystructure.h"

using namespace Commands;

DAddClassCommand::DAddClassCommand(ClassType type, const QString& className, Access inhType, 
		DDocument* pDoc, DClassEntity* pBaseClass, QUndoCommand* pParentCommand)
		: QUndoCommand(pParentCommand)
		, m_pBaseClass(pBaseClass)
		, m_pDoc(pDoc)
{
	DEntityFactory factory;
	m_pClass = factory.createClassEntity(type, className, inhType);
}

void DAddClassCommand::redo()
{
	m_pDoc->addClass(m_pClass, m_pBaseClass);
}

void DAddClassCommand::undo()
{
	m_pDoc->removeClass(m_pClass);
}

///////////////////// DRemoveClassCommand //////////////////

DRemoveClassCommand::DRemoveClassCommand(DClassEntity* pClass, DDocument* pDoc, QUndoCommand* pParentCommand)
		: QUndoCommand(pParentCommand) 
	    , m_pClass(pClass)
		, m_pDoc(pDoc)
{
	m_pBaseClass = pClass->baseClass();
}

void DRemoveClassCommand::redo()
{
	m_pDoc->removeClass(m_pClass);
}

void DRemoveClassCommand::undo()
{
	m_pDoc->addClass(m_pClass, m_pBaseClass);
}